package com.example.video.video_server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.video.common.Constant;
import com.example.video.common.util.ResponseWrap;
import com.example.video.common.util.ResponseWrapUtil;
import com.example.video.video_server.entity.VideoCategory;
import com.example.video.video_server.entity.dto.VideoCategoryDto;
import com.example.video.video_server.entity.vo.VideoCategoryVo;
import com.example.video.video_server.service.IVideoCategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 视频类别表 前端控制器
 * </p>
 *
 * @author yj
 */
@RestController
@RequestMapping("/video/category")
public class VideoCategoryController {

    @Autowired
    private IVideoCategoryService iVideoCategoryService;

    @PostMapping("/add")
    @ApiOperation(value = "新增视频类别")
    public ResponseWrap<VideoCategory> add(@RequestBody VideoCategoryDto videoCategory){
        boolean save = iVideoCategoryService.add(videoCategory);
        return ResponseWrapUtil.success();
    }

    @PostMapping ("/update")
    @ApiOperation(value = "修改视频类别")
    public ResponseWrap<VideoCategory> update(@RequestBody VideoCategoryDto videoCategory){
        boolean update = iVideoCategoryService.updateCategory(videoCategory);
        return ResponseWrapUtil.success();
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "删除视频类别")
    public ResponseWrap<VideoCategory> del(Integer id){
        boolean b = iVideoCategoryService.del(id);
        return ResponseWrapUtil.success();
    }

    @GetMapping("/getDetails")
    @ApiOperation(value = "获取视频类别详情")
    public ResponseWrap<VideoCategoryVo> getDetails(Integer id){
        VideoCategoryVo videoCategory = iVideoCategoryService.getDetails(id);
        return ResponseWrapUtil.success(videoCategory);
    }

    @GetMapping("/getList")
    @ApiOperation(value = "条件查询视频类别列表")
    public ResponseWrap<List<VideoCategoryVo>> getList(VideoCategory videoCategory){
        List<VideoCategoryVo> list = iVideoCategoryService.getCategoryVoList(videoCategory.setStatus(Constant.Status.ENABLE.value));
        return ResponseWrapUtil.success(list);
    }

    @GetMapping("/getPaginationList")
    @ApiOperation(value = "条件分页查询视频类别列表")
    public ResponseWrap<Page> getPaginationList(Integer pageSize, Integer pageIndex, VideoCategory videoCategory){
        Page page = iVideoCategoryService.getPaginationList(new Page(pageIndex, pageSize),videoCategory);
        return ResponseWrapUtil.success(page);
    }
}

